﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HSDc.RingleFlow.Api.Kernel.Org;
using HSDc.RingleFlow.Kernel.DBPersit.DbOrg.Dao;

namespace HSDc.RingleFlow.Kernel.DBPersit.DbOrg
{
    internal class Emp: IEmp
    {
        protected string _Id;
        protected string _userId;
        protected string _Name;
        protected string _Email;

        protected List<IDept> _dept = new List<IDept>();

        protected EmpDao dao = null;

        internal Emp(string _Id, string _userId, string _Name, string _Email)
        {
            this._Id = _Id;
            this._userId = _userId;
            this._Name = _Name;
            this._Email = _Email;
        }

        string IEmp.Id
        {
            get { return _Id; }
        }

        string IEmp.UserId
        {
            get { return _userId; }
        }

        string IEmp.Name
        {
            get { return _Name; }
        }

        string IEmp.Email
        {
            get { return _Email; }
        }

        IManager IEmp.DirectManager
        {
            get 
            {
                RetrieveMainDepartment();
                return _dept[0].MainManager;
            }
        }

        IDept IEmp.MainDepartment
        {
            get 
            {
                RetrieveMainDepartment();
                return _dept[0];
            }
        }

        List<IDept> IEmp.PartimeDepartment
        {
            get 
            {
                RetrievePartimeDepartment();
                return _dept; 
            }
        }

        protected void RetrieveMainDepartment()
        {
            if (dao == null)
                dao = new EmpDao();
            _dept.Clear();
            DepartmentDto dept = dao.RetrieveEmpMainDept(_userId);
            _dept.Add(new Department(dept.Dept_ID, dept.Dept_OrgID, dept.Dept_Name));
        }

        protected void RetrievePartimeDepartment()
        {
            if (dao == null)
                dao = new EmpDao();
            _dept.Clear();
            List<DepartmentDto> depts = dao.RetrieveEmpPartimeDept(_userId);
            foreach (DepartmentDto dept in depts)
                _dept.Add(new Department(dept.Dept_ID, dept.Dept_OrgID, dept.Dept_Name));
        }


        string IEmp.Role
        {
            get { return string.Empty; }
        }
    }
}
